package com.longshine.downcomp;

import com.longshine.platform.equip.tcp.ProtocolDispacher;
import com.longshine.platform.equip.tcp.ProtocolUtil;
import com.longshine.tools.util.NumberUtil;
import com.longshine.tools.util.StrTmpUtil;

public class RecognitionSystem extends EquipSystem{

	public RecognitionSystem(int systemType, int downNo) {
		super(systemType, downNo);
	}
	@Override
	public void recvCommand(int taskId, int functionCode, String dataArea)
			throws Exception {
		if(functionCode == ProtocolDispacher.FUNCTION_LOCATE_BATTERY){
			dataArea = StrTmpUtil.tcpStrExchangeSeqence(dataArea);
			String sAction = dataArea.substring(4,6);
			String sBerthNo = sAction;
			dataArea = dataArea.substring(6);
			dataArea = NumberUtil.toHexStr(1, 1) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = NumberUtil.float2Hex(0.1f) + dataArea;
			dataArea = StrTmpUtil.tcpStrExchangeSeqence(dataArea);
			conn.sendStr(ProtocolUtil.createProtocol(downNo, taskId, systemType, functionCode, dataArea));
			int action = NumberUtil.hex2Decimal(sAction);
			if(action == 1){
				System.out.println("上报测距");
				conn.sendStr(ProtocolUtil.createProtocol(downNo, 0, systemType, ProtocolDispacher.FUNCTION_SENSOR_UPLOAD, sBerthNo));
			}
		}
	}

	public static void main(String[] args) throws Exception{
		//System.out.println(NumberUtil.hex2Float(NumberUtil.float2Hex(2f)));
		new RecognitionSystem(1,2).startWork();
	}
}
